package fudan.se.project.domain.conference.production;


import com.fasterxml.jackson.annotation.JsonIgnore;
import fudan.se.project.domain.conference.Conference;
import fudan.se.project.domain.conference.Topic;
import fudan.se.project.domain.conference.role.Author;
import lombok.*;

import javax.persistence.*;
import java.util.*;

import static fudan.se.project.domain.conference.production.Paper.PaperState.WAITING;

@Entity
@Getter
@Setter
@RequiredArgsConstructor
@NoArgsConstructor
public class Paper {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NonNull
    @Lob
    private String titleText;
    @NonNull
    @Lob
    private String abstractText;

    @NonNull
    @Lob
    private String originalFilename;

    @Enumerated(EnumType.STRING)
    private PaperState paperState = WAITING;

    private Date dateSubmitted = new Date();

    @JsonIgnore
    @NonNull
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
    private Author author;

    @JsonIgnore
    @NonNull
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.MERGE)
    private Conference conference;

    @JsonIgnore
    @ManyToMany(fetch = FetchType.LAZY)
    private Set<Topic> topics = new HashSet<>();

    @JsonIgnore
    @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}, mappedBy = "paper")
    private List<Writer> writers = new LinkedList<>();

    @JsonIgnore
    @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}, mappedBy = "paper")
    private Set<ReviewInfo> reviewInfos = new HashSet<>();


    public enum PaperState {
        WAITING,
        REVIEWING,
        COMPLETED
    }

    public void addTopics(Collection<Topic> topics) {
        this.topics.addAll(topics);
    }
}
